<form class="main" name="form1" method="post" action="/address/editpresale?oid=<?php echo $this->oid;?>" onSubmit="return check()">
<a href="/address/presale?oid=<?php echo $this->oid;?>" >
	<div class="topBack" style="padding:8.5px 0 ;color:gold;text-align:center;">取消</div>
</a>
<div class="topContent" style="line-height:30px;">
	<p>新增地址</p>
	<p style="font-size:0.7em;line-height:0.1px;">微信安全支付</p>
</div>
<div class="topRight">
	<input type="submit" style="color:gold" value="保存"/>
</div>
<div class="clear"></div>
<div class="clear" style="padding:6px 0;background-color:#F2F2F2"></div>
<center>
	<div class="xiahua">
		<div class="xiahua-left">收货人</div>
		<div class="xiahua-input">
			<input type="text" id="contact" placeholder="必填" name="text1" class="input_key" require-notice=""/>
			<span  class="cl"><img src="/images/clear.png"/></span>
		</div>
	</div>
	<div class="clear"></div>
	
	<div class="xiahua">
		<div class="xiahua-left">手机号码</div>
		<div class="xiahua-input">
			<input type="text" id="mobile" placeholder="必填" name="text2" class="input_key"/>
			<span  class="cl"><img src="/images/clear.png"/></span>
		</div>
	</div>
	<div class="clear"></div>
	
	<div class="xiahua"><div class="xiahua-left">选择地区</div>
		<div class="xiahua-input" style="font-size:0.9em;width:52%;padding-top:10px;"><input id="procity" type="hidden"  name="text3"/>
			<select id='provinceSelecter' onchange="provicedChanged(this.options[this.options.selectedIndex]);">
				<option value="">请选择</option>
			<?php
				if(!empty($this->provinces)){
					foreach($this->provinces as $p){
						$isdel = $p->isdel;
						$active = $p->active;
						$addId = $p->id;
						$addName = $p->name;
						if($isdel=='0'  && $addId!='1'){
							echo '<option value="'.$addId.'">'.$addName.'</option>';
						}
					}
				}
			?>
			</select>
			<select id="citySelecter" onchange="cityChanged(this.options[this.options.selectedIndex]);"></select>
			<select id="districtSelecter" onchange="districtChanged(this.options[this.options.selectedIndex]);"></select>
		</div>
		<div id="div3" style="width:32%"></div>
	</div>
	<div class="clear"></div>
	<div class="xiahua">
		<div class="xiahua-left">详细地址</div>
		<div class="xiahua-input">
			<textarea id="detailAdd" type="text" placeholder="必填" style="padding-top:5px;resize:none;border:none;width:92%;float:left;" name="text4" class="input_key"></textarea><span class="cl" style="margin-top:8px"><img src="/images/clear.png"/></span>
		</div>
	</div>
	<div class="clear"></div>
	
	<div class="xiahua">
		<div class="xiahua-left">邮政编码</div>
		<div class="xiahua-input">
			<input id="email" type="text" placeholder="选填" name="text5" class="input_key"/><span  class="cl"><img src="/images/clear.png"/></span>
		</div>
	</div>
    <div class="clear"></div>
	</center>
</form>

<!--
<div class="main3" style="display:none;">
	<div class="addr_title">选择地区</div><div class="addr_close">X</div>
	<div style="border-bottom:1px solid #BFBFBF;font-size:0.87em;magin-top:20px;">
		<span style="padding:8px 7px 0 7px;border-bottom:2px solid #60AB34" id="tab1" onclick="myclick(1,'选择省份')">选择省份</span>
		<span style="padding:8px 7px 0 7px" id="tab2" onclick="myclick(2,'选择城市')">选择城市</span>
		<span style="padding:8px 7px 0 7px" id="tab3" onclick="myclick(3,'选择行政区')">选择行政区</span>
	</div>
	<div id="wrapperAdd" class="wrapperComman" style="top:70px;bottom:0px;">
	<div style="width:100%;">
		<div style="width:100%;" class="tab_css" id="tab1_content" style="display:block">
			<?php 
				if(!empty($this->provinces)){
					foreach($this->provinces as $p){
						$isdel = $p->isdel;
						$active = $p->active;
						$addId = $p->id;
						$addName = $p->name;
						if($isdel=='0'  && $addId!='1'){
							echo '<div onclick="javascript:selectProvince(this);return false;" addid="'.$addId.'" addName="'.$addName.'" style="padding:8px;font-size:0.8em;">'.$addName.'</div>';
						}
					}
				}
			?>
		</div>
		<div style="width:100%;" class="tab_css" id="tab2_content" style="display:none"></div>  
		<div style="width:100%;" class="tab_css" id="tab3_content" style="display:none"></div>
	</div>
	</div>
</div>
-->
<script type="text/javascript">
	window.onload = function(){
		tab2 = $('#citySelecter');
		tab3 = $('#districtSelecter');
		tab2.hide();
		tab3.hide();

	};

    function provicedChanged(el){
		$('#div3').html('');
		tab1 = $('#provinceSelecter');
		tab2 = $('#citySelecter');
		tab3 = $('#districtSelecter');
		procity = $('#procity');
		procity.prop("provinceName",el.innerHTML);
		procity.prop("cityName"," ");
		procity.prop("districtName"," ");
		procity.val(procity.prop('provinceName')+' '+procity.prop('cityName')+' '+procity.prop('districtName'));
		tab2.hide();
		tab3.hide();
                provinceId = el.value;
		if(provinceId>0){
			$.ajax({
				type: "post",
				url : "/address/cityinfo",
				dataType:'json',
				data:{'provinceId':provinceId},
				success: function(info){
					if (info.msg == 'success'){
						list = info.list;
						if (list.length > 0) {
							tab2.empty();
							tab2.show();
							html = '<option value="0">请选择</option>';
							list.forEach(function(e){
								 html += '<option value="'+e.id+'">'+e.name+'</option>';
							});
							tab2.html(html);
						}
					} else {
						alert('请重试！');
					}
				},
				error: function(){
					alert('网络异常，请重试！');
				}
			});
		}
        }

    function cityChanged(el){
		$('#div3').html('');
		tab1 = $('#provinceSelecter');
		tab2 = $('#citySelecter');
		tab3 = $('#districtSelecter');
		procity.prop("cityName",el.innerHTML);
		procity.prop("districtName"," ");
		procity.val(procity.prop('provinceName')+' '+procity.prop('cityName')+' '+procity.prop('districtName'));
		tab3.hide();
		cityId = el.value;
		if(cityId > 0){
			$.ajax({
				type: "post",
				url : "/address/districtinfo",
				dataType:'json',
				data:{'cityId':cityId},
				success: function(info){
					if (info.msg == 'success'){
						list = info.list;
						if (list.length > 0) {
							tab3.show();
							tab3.empty();
							html = '<option value="0">请选择</option>';
							list.forEach(function(e){
								 html += '<option value="'+e.id+'">'+e.RegionName+'</div>';
							});
							tab3.html(html);
						}
					} else {
						alert('请重试！');
					}
				},
				error: function(){
					alert('网络异常，请重试！');
				}
			});
		}
        }

        function districtChanged(el){
		$('#div3').html('');
		tab1 = $('#provinceSelecter');
		tab2 = $('#citySelecter');
		tab3 = $('#districtSelecter');
		procity.prop("districtName",el.innerHTML);
		procity.val(procity.prop('provinceName')+' '+procity.prop('cityName')+' '+procity.prop('districtName'));
        }
		
	var tel,name1,addr,detailaddr,youbian;
    function checkname(){
		$('#contact').attr('placeholder','必填');
        name1 = document.form1.text1.value;
        if (name1 == "") {
			$('#contact').attr('placeholder','收货人不能为空！');
            document.form1.text1.focus();
            return false;
        }
        if (name1.length > 16) {
			$('#contact').val('');
            $('#contact').attr('placeholder','姓名输入1-16个字符！');
            //document.form1.text1.focus();
            return false;
        }
		
        return true;
        
    }

    function checktel(){
			 $('#mobile').attr('placeholder','必填');
             tel = document.form1.text2.value;
             if (tel == "") {
			   $('#mobile').attr('placeholder','手机号码不能为空！');
               document.form1.text2.focus();
               return false;
             }
			 if(tel.length!=11){
			 	$('#mobile').val('');
				$('#mobile').attr('placeholder','请输入正确的手机号');
			 	document.form1.text2.focus();
                return false;
			 }
			 var myreg=/^1[3|4|5|7|8][0-9]\d{4,8}$/;
			 if(tel.match(myreg)==null){
				 $('#mobile').val('');
				 $('#mobile').attr('placeholder','请输入正确的手机号');
				 document.form1.text2.focus();
				 return false;
			 }
			 return true;
    }
	
	
	function checkaddr(){
		var div = document.getElementById("div3");
              div.innerHTML = "";
              addr = document.form1.text3.value;
              if (addr == "") {
                  div.innerHTML = "地区不能为空！";
                  document.form1.text3.focus();
                  return false;
              }
		return true;
	}
	
    function checkdetailaddr(){
		$('#detailAdd').attr('placeholder','必填');
        detailaddr = document.form1.text4.value;
        if (detailaddr == "") {
			$('#detailAdd').attr('placeholder','请输入详细地址！');
			document.form1.text4.focus();
            return false;
        }
	    return true;
	}
	
	
    function check(){
        if (checkname() && checktel() && checkaddr() && checkdetailaddr()) {
			return true;
        }
         else {
             return false;
        }
    }
	
	$(function(){ 
        $(".cl").click(function(){
        $(this).siblings("").val("");
        $(this).siblings("input").focus();
        $(this).hide();
        })
		var tValue;
		$(".input_key").keydown(function(){
			if ($(".input_key").val().trim()!="") {
				$(this).siblings("").show();    
			}
		});
		$(".input_key").keyup(function(){
			if ($(".input_key").val().trim()!="") {
				$(this).siblings("").show();
			}
		});
    })

</script>
